﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
using System.Data.SqlClient;
namespace Data
{
    public class MediaForecast
    {
        /// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey = "Id";
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.MediaForecast model)
        {
            return new DataAccess().Add<Model.MediaForecast>(model, primaryKey);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.MediaForecast model)
        {
            return new DataAccess().Update<Model.MediaForecast>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.MediaForecast>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.MediaForecast GetModel(long Id)
        {
            return new DataAccess().Get<Model.MediaForecast>(Id, primaryKey);
        }

        public Model.MediaForecast GetModelBysql(string sql)
        {
            return new DataAccess().Get<Model.MediaForecast>(sql);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.MediaForecast>(primaryKey);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.MediaForecast> GetPageList_Where(int PageIndex, int PageSize, string sqlwhere, out int totalCount)
        {
            totalCount = new DataAccess().GetCount<Model.MediaForecast>(primaryKey, sqlwhere);
            return new DataAccess().GetPage_List<Model.MediaForecast>(PageIndex, PageSize, primaryKey, primaryKey + " asc", sqlwhere);
        }

        public List<Model.MediaForecast> GetPageList_Where1(int PageIndex, int PageSize, string sqlwhere)
        {
            return new DataAccess().GetPage_List<Model.MediaForecast>(PageIndex, PageSize, primaryKey, primaryKey + " asc", sqlwhere);
        }
        public DataTable GetPageDT_Where(int PageIndex, int PageSize, string sql, out int totalCount)
        {
            string strWhere = sql.ToString();
            totalCount = new DataAccess().GetCount<Model.MediaForecast>(primaryKey, strWhere);
            return ConvertHelper<Model.MediaForecast>.ConvertToDT(new DataAccess().GetPage_List<Model.MediaForecast>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere));
        }

        public int GetTotalCount(string sqlwhere)//查数据总条数
        {
            int totalCount = new DataAccess().GetCount<Model.MediaForecast>(primaryKey, sqlwhere);
            return totalCount;
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.MediaForecast>(Ids, primaryKey);
        }
        //------------------------------扩展-----------------------------------------
        public int CreateForecast(long userid, string username, int lotteryType, string lotteryQs, string ForecastNo)
        {
            SqlParameter[] p = {
                               new SqlParameter("@MediaUserId",userid),
                               new SqlParameter("@MediaName",username),
                               new SqlParameter("@LotteryType",lotteryType),
                               new SqlParameter("@LotteryQS",lotteryQs),
                               new SqlParameter("@ForecastNo",ForecastNo)
                               };
            return DbHelp.ExecuteNonQuery(DBConfig.ConnectionSettings, CommandType.StoredProcedure, "pro_MediaForecast_add", p);
        }

        //public List<Model.MediaForecaststatistics> GetMediaForecaststatistics(int lotteryType,string lotteryQs)
        //{
        //    SqlParameter[] p = {
        //        new SqlParameter("@LotteryType",lotteryType),
        //        new SqlParameter("@LotteryQS",lotteryQs)
        //    };
        //    List<Model.MediaForecaststatistics> list = new List<Model.MediaForecaststatistics>();
        //    SqlDataReader dr = DbHelp.ExecuteDataRead(DBConfig.ConnectionSettings, CommandType.StoredProcedure, "GetMediaForecaststatistics", p);
        //    while(dr.Read())
        //    {
        //        Model.MediaForecaststatistics item = new Model.MediaForecaststatistics();
        //        #region 
        //        item.LotteryNo = dr["LotteryNo"].ToString();
        //        item.rnum1 = (int)dr["rnum1"];
        //        item.rnum2 = (int)dr["rnum2"];
        //        item.rnum3 = (int)dr["rnum3"];
        //        item.rnum4 = (int)dr["rnum4"];
        //        item.rnum5 = (int)dr["rnum5"];
        //        item.rnum6 = (int)dr["rnum6"];
        //        item.rnum7 = (int)dr["rnum7"];
        //        item.rnum8 = (int)dr["rnum8"];
        //        item.rnum9 = (int)dr["rnum9"];
        //        item.rnum10 = (int)dr["rnum10"];
        //        item.rnum11 = (int)dr["rnum11"];
        //        item.rnum12 = (int)dr["rnum12"];
        //        item.rnum13 = (int)dr["rnum13"];
        //        item.rnum14 = (int)dr["rnum14"];
        //        item.rnum15 = (int)dr["rnum15"];
        //        item.rnum16 = (int)dr["rnum16"];
        //        item.rnum17 = (int)dr["rnum17"];
        //        item.rnum18 = (int)dr["rnum18"];
        //        item.rnum19 = (int)dr["rnum19"];
        //        item.rnum20 = (int)dr["rnum20"];
        //        item.rnum21 = (int)dr["rnum21"];
        //        item.rnum22 = (int)dr["rnum22"];
        //        item.rnum23 = (int)dr["rnum23"];
        //        item.rnum24 = (int)dr["rnum24"];
        //        item.rnum25 = (int)dr["rnum25"];
        //        item.rnum26 = (int)dr["rnum26"];
        //        item.rnum27 = (int)dr["rnum27"];
        //        item.rnum28 = (int)dr["rnum28"];
        //        item.rnum29 = (int)dr["rnum29"];
        //        item.rnum30 = (int)dr["rnum30"];
        //        item.rnum31 = (int)dr["rnum31"];
        //        item.rnum32 = (int)dr["rnum32"];
        //        item.rnum33 = (int)dr["rnum33"];
        //        item.rnum34 = (int)dr["rnum34"];
        //        item.rnum32 = (int)dr["rnum35"];
        //        item.bnum1 = (int)dr["bnum1"];
        //        item.bnum2 = (int)dr["bnum2"];
        //        item.bnum3 = (int)dr["bnum3"];
        //        item.bnum4 = (int)dr["bnum4"];
        //        item.bnum5 = (int)dr["bnum5"];
        //        item.bnum6 = (int)dr["bnum6"];
        //        item.bnum7 = (int)dr["bnum7"];
        //        item.bnum8 = (int)dr["bnum8"];
        //        item.bnum9 = (int)dr["bnum9"];
        //        item.bnum10 = (int)dr["bnum10"];
        //        item.bnum11 = (int)dr["bnum11"];
        //        item.bnum12 = (int)dr["bnum12"];
        //        item.bnum13 = (int)dr["bnum13"];
        //        item.bnum14 = (int)dr["bnum14"];
        //        item.bnum15 = (int)dr["bnum15"];
        //        item.bnum16 = (int)dr["bnum16"];
        //        list.Add(item);
        //        #endregion
        //    }
        //    dr.Close();
        //    return list;

        //}
        public List<Model.MediaForecast> GetList(string Sql)
        {
            return new DataAccess().GetList<Model.MediaForecast>(Sql);
        }

        public DataTable GetPageListBysql(string sql)
        {
            return DbHelp.ExecuteDataset(DBConfig.ConnectionSettings, CommandType.Text, sql, null).Tables[0];
        }
        public int Update1(string zred, string zblue, int level, long userid, int lotteryType, string lotteryQs, string LotteryNo, DateTime addTime)
        {
            string sqlUpd = "Update MediaForecast set Mredball=@Mredball,Mblueball=@Mblueball,WinLevel=@WinLevel,LotteryNo=@LotteryNo,Opentime=@Opentime where MediaUserId=@MediaUserId and  LotteryType=@LotteryType and LotteryQS=@LotteryQS";
            SqlParameter[] p = {
                               new SqlParameter("@Mredball",zred),
                               new SqlParameter("@Mblueball",zblue),
                               new SqlParameter("@WinLevel",level),
                               new SqlParameter("@MediaUserId",userid),
                               new SqlParameter("@LotteryType",lotteryType),
                               new SqlParameter("@LotteryQS",lotteryQs),
                               new SqlParameter("@LotteryNo",LotteryNo),
                               new SqlParameter("@Opentime",addTime)
            };
            return DbHelp.ExecuteNonQuery(DBConfig.ConnectionSettings, CommandType.Text, sqlUpd, p);
        }

    }
}
